// hyb_yl/mysubpages/pages/fenzu/fenzu.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    serchList: [],
    labelList: [],
    label_index: 0,
    delfezu: [],
  },
  label_btn: function (e) {
    var index = e.currentTarget.dataset.index
    var text = this.data.labelList[index]

    this.setData({
      label_index: index,
      text: text
    })
  },
  label_input: function (e) {
    console.log(e.detail.value)
    var newLabel = e.detail.value
    this.setData({
      newLabel: newLabel
    })
  },
  remove_tab: function (e) {
    var index = e.currentTarget.dataset.index;
    var id = e.currentTarget.dataset.id;
    app.util.request({
      'url':"entry/wxapp/follow.del_fenzu",
      data:{
        id:id,
        zid:that.data.zid
      },
      success:function(res)
      {
        wx.showToast({
          title: res.data.message,
        })
        that.getList();
      }
    })
  },
  add_label: function () {
    this.setData({
      show_addlabel: true
    })
  },
  close_btn: function () {
    this.setData({
      show_addlabel: false
    })
  },
  add_btn: function (e) {
    var that = this;
    var newLabel = that.data.newLabel
    if (!newLabel) {
      wx.showToast({
        title: '请输入分组名称',
        icon: 'none'
      })
    } else {
      app.util.request({
        'url':"entry/wxapp/follow.add_fenzu",
        data:{
          title:newLabel,
          zid:that.data.zid,
          pid:that.data.pid
        },
        success:function(res)
        {
          wx.showToast({
            title: res.data.message,
          })
          that.setData({
            show_addlabel: false
          })
          that.getList();
        }
      })
      
    }
  },
  serch: function (e) {
    var serch_text = e.detail.value
    var list = this.data.list
    var arr = []
    for (var i = 0; i < list.length; i++) {
      if (list[i].title.indexOf(serch_text) != -1) {
        arr.push(list[i])
      }
    }
    this.setData({
      serchList: arr
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var zid = options.zid
    that.setData({
      zid: zid,
    })
    that.getList();
  },
  getList:function(){
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/follow.zhuanjia_fenzus',
      data: {
        zid: that.data.zid
      },
      success: function (res) {
        that.setData({
          list:res.data
        })
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  queding(e) {
    var that = this
    wx.navigateBack({})

  }
})